package com.linln.admin.roadrescue;

import com.linln.common.utils.DateUtil;
import com.linln.common.vo.JsonResult;
import com.linln.common.vo.PageResult;
import com.linln.component.shiro.ShiroUtil;
import com.linln.modules.insurance.domain.InsuranceOffer;
import com.linln.modules.insurance.service.InsuranceOfferService;
import com.linln.modules.roadrescue.domain.RoadRescue;
import com.linln.modules.roadrescue.service.RoadRescueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.admin.roadrescue
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.admin.roadrescue
 * @Description: TODO
 * @date Date : 2021年01月07日 10:30
 */
@Controller
@RequestMapping("roadRescue")
public class RoadRescueController {
    @GetMapping("/index")
    public String index() {
        return "/roadRescue/index";
    }

    @Autowired
    private RoadRescueService roadRescueService;

    @GetMapping
    @ResponseBody
    public PageResult<RoadRescue> getRoadRescue(@RequestParam(required = false, defaultValue = "0") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit, String search, Integer status) {
        return roadRescueService.getRoadRescue(page, limit, search, status);
    }


    @PostMapping
    @ResponseBody
    public JsonResult addRoadRescue(RoadRescue roadRescue) {
        roadRescue.setAlarmDate(DateUtil.formatDate(new Date()));
        return roadRescueService.addRoadRescue(roadRescue) ? JsonResult.ok("保存成功") : JsonResult.error("保存失败");
    }


    @PostMapping("/updateStatus")
    @ResponseBody
    public JsonResult updateStatus(String rrId,Integer status,String statusNotes,String handlerDate) {

        return roadRescueService.updateRoadRescueStatus(rrId,status,statusNotes,handlerDate) ? JsonResult.ok("修改成功") : JsonResult.error("修改失败");
    }
}
